home *** CD-ROM | disk | FTP | other *** search
- # Jedi Knight Missions Cog Script
- #
- # WEAP_EWEB_M.COG
- #
- # WEAPON 10 script - EWEB Gun
- #
- # Player can not move when using this weapon.
- #
- # - Affected by MagSealed sectors/surfaces.
- #
- # [YB & CYW]
- #
- # (C) 1997 LucasArts Entertainment Co. All Rights Reserved
-
-
- symbols
-
- sound mountSound=df_rif_ready.wav local
- sound dismountSound=PutWeaponAway01.wav local
- sound fireSoundSmall=EWEBFireSm1.wav local
- sound fireSoundLarge=EWEBFireBig1.wav local
- sound outSound=trprout.wav local
-
- template projectile=+EWEBRound local
- template EWEBProper=+EWEB local
- template EWEBRider=+EWEBRider local
- template tempGhost=ghost local
-
- thing player local
- thing thingEWEB=-1 local
- thing thingRider local
- thing ghostRider local
-
- vector tempvec local
- vector tempvec2 local
- flex tempflex local
- flex tempflex2 local
- flex tempflex3 local
-
- flex distortionRange local
- flex fireWait=0.1 local
- flex powerBoost local
- flex autoAimFOV=1 local
-
- flex fOldMaxPitch local
- flex fOldMinPitch local
-
- int attachFlags local
-
- int iFirstCamera local
-
- thing dummy local
- thing rummy local
-
- int fireChannel=-1 local
- int mode local
-
- int imOnIt=0 local
-
- int iLastWeapon local
- vector vLastPosition local
- sector sLastSector local
- thing tEWEBPowerup local
-
- flex fOldMass local
-
- int iDoItNextTime=0 local
-
- message playeraction
- message killed
- message activated
- message deactivated
- message selected
- message deselected
- message autoselect
- message fire
- message damaged
- message timer
- message join
-
- end
-
- # ========================================================================================
-
- code
-
- fire:
- player = GetSourceRef();
- mode = GetSenderRef();
-
- // Check that the player is still alive.
- if(GetThingHealth(player) <= 0)
- {
- Return;
- }
-
- // Check Ammo - If we are out, autoselect best weapon.
- if(GetInv(player, 92) < 1.0)
- {
- PlaySoundThing(outSound, player, 1.0, -1, -1, 0x80);
-
- DeactivateWeapon(player, mode);
-
- if((GetAutoSwitch() & 1))
- SelectWeapon(player, GetWeaponBin(AutoSelectWeapon(player, 1)));
- Return;
- }
-
- // Calculate how much the weapon's accuracy has been affected by damage.
- // distortionRange = (100.0 - GetInv(player, GetWeaponBin(10))) / 3.0;
- distortionRange = 0.0;
-
- SetPOVShake('0.0 -.003 0.0', '1.5 0.0 0.0', .05, 80.0);
- if (mode == 1)
- {
- // Get random aiming error
- randVec = VectorSet((Rand()-0.5)*distortionRange, (Rand()-0.5)*distortionRange, 0.0);
- SetCollideType(player, 0);
- dummy = FireProjectile(ghostRider, projectile, -1, 8, '0.0 0.15 0.0', randVec, 1.0, 0x31, autoAimFOV, 0.01);
- PlaySoundThing(fireSoundSmall, player, 1.0, -1, -1, 0x80);
- SetCollideType(player, 1);
-
- ChangeInv( player, 92, -1.0 );
- }
- else
- {
- SetCollideType(player, 0);
- randVec = VectorSet(((Rand()-0.5)*distortionRange)-1.0, ((Rand()-0.5)*distortionRange)-1.0, 0.0);
- dummy = FireProjectile(ghostRider, projectile, -1, 8, '0.0 0.15 0.0', randVec, 1.0, 0x31, autoAimFOV, 0.01);
- PlaySoundThing(fireSoundLarge, player, 1.0, -1, -1, 0x80);
-
- // Fire as many projectiles as we have ammo for.
- if (GetInv(player, 92) >= 2.0)
- {
- randVec = VectorSet(((Rand()-0.5)*distortionRange)-1.0, ((Rand()-0.5)*distortionRange)+1.0, 0.0);
- rummy = FireProjectile(ghostRider, projectile, 0, 8, '0.0 0.15 0.0', randVec, 1.0, 0x31, autoAimFOV, 0.01);
-
- if (GetInv(player, 92) >= 3.0)
- {
- randVec = VectorSet(((Rand()-0.5)*distortionRange)+1.0, ((Rand()-0.5)*distortionRange)-1.0, 0.0);
- rummy = FireProjectile(ghostRider, projectile, 0, 8, '0.0 0.15 0.0', randVec, 1.0, 0x31, autoAimFOV, 0.01);
-
- if (GetInv(player, 92) >= 4.0)
- {
- randVec = VectorSet(((Rand()-0.5)*distortionRange)+1.0, ((Rand()-0.5)*distortionRange)+1.0, 0.0);
- rummy = FireProjectile(ghostRider, projectile, 0, 8, '0.0 0.15 0.0', randVec, 1.0, 0x31, autoAimFOV, 0.01);
- }
- }
- }
-
- SetCollideType(player, 1);
-
- ChangeInv( player, 92, -4.0 );
- }
-
- powerBoost = GetInv(player, 63);
- ChangeFireRate(player, fireWait/powerBoost);
-
- Return;
-
- # ........................................................................................
-
- activated:
- player = GetSourceRef();
- mode = GetSenderRef();
-
- if (mode == 0)
- fireWait = 0.4;
- else
- if (mode == 1)
- fireWait = 0.1;
-
- powerBoost = GetInv(player, 63);
- ActivateWeapon(player, fireWait/powerBoost, mode);
- Return;
-
- # ........................................................................................
-
- deactivated:
- player = GetSourceRef();
- DeactivateWeapon(player, mode);
- Return;
-
- # ........................................................................................
-
- selected:
- if (!imOnIt)
- {
- imOnIt = 1;
-
- player = GetSourceRef();
-
- sLastSector = GetThingSector(player);
- vLastPosition = GetThingPos(player);
- iLastWeapon = GetCurWeapon(player);
- tEWEBPowerup = GetInv(player, GetWeaponBin(10));
-
- iFirstCamera = GetCurrentCamera();
- SetCurrentCamera(0);
-
- StopThing(player);
- SetThingPosEx(player, GetThingPos(tEWEBPowerup), GetThingSector(tEWEBPowerup));
- SetActorFlags(player, 0x8000000); // Freeze the player
-
- // Make the powerup non-collide and invisible.
- SetThingCollide(tEWEBPowerup, 0);
- SetThingFlags(tEWEBPowerup, 0x10);
-
- // Don't arm instantly...
- SetTimerEx(0.2, 0, 0, 0);
- }
-
- return;
-
- # ........................................................................................
-
- timer:
- if (GetSenderID() == 0)
- {
- PlayMode(player, 41);
- PlaySoundThing(mountSound, player, 1.0, -1, -1, 0x80);
- SetArmedMode(player, 1);
- jkSetWeaponMesh(player, -1);
- jkClearFlags(player, 0x5);
- SetCurWeapon(player, GetWeaponBin(10));
-
- StopThing(player);
- // SetThingPosEx(player, GetThingPos(tEWEBPowerup), GetThingSector(tEWEBPowerup));
- SetActorFlags(player, 0x8000000); // Freeze the player
-
- // Make the main player thing invisible.
- SetThingFlags(player, 0x10);
-
- thingEWEB = CreateThing(EWEBProper, player);
- thingRider = CreateThing(EWEBRider, player);
- ghostRider = CreateThing(tempGhost, player);
-
- // Make the rider look like the player
- SetThingModel(thingRider, GetThingModel(player));
-
- fOldMaxPitch = SetThingMaxHeadPitch(player, 30.0);
- fOldMinPitch = SetThingMinHeadPitch(player, -30.0);
-
- AttachThingToThing(thingEWEB, player);
- AttachThingToThing(thingRider, player);
- AttachThingToThing(ghostRider, player);
-
- fOldMass = GetThingMass(player);
- SetThingMass(player, 0.0);
-
- // Move the rider up a bit.
- tempvec = GetThingPos(ghostRider);
- tempvec = VectorAdd(tempvec, vectorset(0, 0, 0.25));
- SetThingPos(ghostRider, tempvec);
-
- iDoItNextTime = 1;
- SetActionCog(GetSelfCog(), 0x80004120);
-
- SetCameraFocus(0, ghostRider);
- }
- else
- if (GetSenderID() == 1)
- {
- if (thingEWEB != -1)
- {
- // SendTrigger(-1, 99002, thingEWEB, GetLocalPlayerThing(), 0, 0);
- SyncThingAttachment(thingEWEB);
- }
- }
-
- Return;
-
- # ........................................................................................
-
- deselected:
- if (imOnIt)
- {
- imOnIt = 0;
-
- player = GetSourceRef();
-
- DeactivateWeapon(player, mode);
-
- SetCurrentCamera(iFirstCamera);
-
- SetInvActivated(player, GetWeaponBin(10), 0);
- SetThingPosEx(player, vLastPosition, sLastSector);
-
- SetThingCollide(tEWEBPowerup, 1);
- ClearThingFlags(tEWEBPowerup, 0x10);
-
- ClearActorFlags(player, 0x8000000); // Unfreeze the player
-
- ClearThingFlags(player, 0x10);
-
- SetThingMass(player, fOldMass);
-
- SetThingMaxHeadPitch(player, fOldMaxPitch);
- SetThingMinHeadPitch(player, fOldMinPitch);
-
- DestroyThing(thingEWEB);
- DestroyThing(thingRider);
- DestroyThing(ghostRider);
-
- thingEWEB = -1;
-
- PlaySoundThing(dismountSound, player, 1.0, -1, -1, 0x80);
-
- SetCameraFocus(0, jkGetLocalPlayer());
-
- SetActionCog(-1, 0);
- }
-
- Return;
-
- # ........................................................................................
-
- autoselect:
- player = GetSourceRef();
-
- // Default to returning -1.
- ReturnEx(-1);
-
- if (IsInvActivated(player, GetWeaponBin(10)))
- {
- // If the player has ammo
- if(GetInv(player, 92) != 0.0)
- {
- attachFlags = GetAttachFlags(player);
-
- // Don't arm if we're not on the ground or
- // if we're in the process of Force jumping.
- if ((attachFlags & 3) && (!IsInvActivated(player, 21)))
- ReturnEx(999.0);
- }
- }
-
- Return;
-
- # ........................................................................................
-
- damaged:
- if (GetCurWeapon(player) == 10) // Only take damage if the EWEB is selected,
- {
- // Knock the player off if we feel like it.
- if (GetParam(0) > (rand() * 100 + 50))
- SelectWeapon(player, GetWeaponBin(AutoSelectWeapon(player, 1)));
-
- if (GetSourceRef()) // if there is a source thing,
- {
- if (GetParam(1) & 6) // this is energy or fire damage,
- {
- // And the shot struck the EWEB.
- tempflex = ThingViewDot(player, GetSourceRef());
- if ((tempflex > 0.70) || (tempflex < -0.70))
- {
- ReturnEx(GetParam(0) / 2);
- Return;
- }
- }
- }
- }
-
- // Shot did not strike the EWEB. Forward all damage.
- ReturnEx(GetParam(0));
-
- Return;
-
- # ........................................................................................
-
- killed:
- if (player == GetSenderRef())
- {
- // If the actor is killed while armed with the
- // EWEB, release the movement inhibitions.
- ClearActorFlags(player, 0x8000000);
-
- SetActionCog(-1, 0);
- }
- Return;
-
- # ........................................................................................
-
- playeraction:
- if (GetParam(0) == 8.0 || GetParam(0) == 5.0) // Pitch or yaw
- iDoItNextTime = 1;
-
- if (GetParam(0) == 31.0) // Frame update
- {
- if (GetThingMass(player) > 0.0) // Detect if a load game has occurred (object mass is not saved)
- {
- // Make some corrections.
- SetThingMass(player, 0.0);
- SetThingMaxHeadPitch(player, 30.0);
- SetThingMinHeadPitch(player, -30.0);
-
- SetThingPosEx(thingEWEB, GetThingPos(tEWEBPowerup), GetThingSector(tEWEBPowerup));
- SetThingLook(thingEWEB, GetThingLVEC(player));
-
- AttachThingToThing(thingEWEB, player);
-
- iDoItNextTime = 1;
- }
-
- if (iDoItNextTime == 1)
- {
- iDoItNextTime = 0;
-
- // Spin the rider around
- tempflex = GetThingJointAngle(thingEWEB, 7);
-
- // Correct some stuff.
- tempvec = GetThingLVecPYR(player);
- tempvec = VectorSet(tempflex, VectorY(tempvec), 0.0);
- SetThingLookPYR(thingRider, tempvec);
- SetThingLookPYR(ghostRider, tempvec);
-
- tempflex3 = tempflex-8.0;
- tempflex2 = (-0.06) * cos(tempflex3);
- tempflex3 = (sin(tempflex) * (-0.060)) + 0.047;
-
- tempflex2 = tempflex2 - (0.12 * sin(tempflex));
-
- tempvec = GetThingPos(player);
- tempvec2 = GetThingLVec(player);
- tempvec2 = VectorScale(tempvec2, tempflex2);
- tempvec = VectorAdd(tempvec, tempvec2);
- tempvec = VectorAdd(tempvec, vectorset(0, 0, tempflex3));
-
- tempvec2 = VectorAdd(tempvec, vectorset(0, 0, ((-0.12) * (1-cos(tempflex)))));
- SetThingPos(thingRider, tempvec2);
-
- tempvec = GetThingPos(player);
- tempvec = VectorAdd(tempvec, '0 0 -0.065');
- tempvec = VectorAdd(tempvec, VectorSet(0, 0, 0.13 * cos(tempflex)));
- tempvec2 = GetThingLVec(player);
- tempvec2 = VectorScale(tempvec2, -0.13 * sin(tempflex));
- tempvec = VectorAdd(tempvec, tempvec2);
- SetThingPos(ghostRider, tempvec);
-
- if (IsMulti())
- SyncThingPos(thingEWEB);
-
- // SetThingPos(thingRider, tempvec);
- }
- }
-
-
- if (GetParam(0) == 14.0) // Other action
- {
- if (GetParam(2) == 0.0) // Everything is OK except cycle camera.
- {
- ReturnEx(0.0);
- return;
- }
- }
-
- if (GetParam(0) == 8.0) // Pitch
- {
- // Pitch the rider
- tempvec = GetThingLVecPYR(player);
- tempvec = VectorSet(GetParam(2), VectorY(tempvec), 0.0);
- SetThingLookPYR(thingRider, tempvec);
- SetThingLookPYR(ghostRider, tempvec);
-
- // Pitch the EWEB
- SetThingJointAngle(thingEWEB, 7, GetParam(2));
-
- // Tell everyone else to pitch their EWEB.
- if (IsMulti())
- SendTrigger(-1, 99003, thingEWEB, 7, GetParam(2), 0);
- }
-
- ReturnEx(1.0);
- Return;
-
- join:
- SetTimerEx(1.0, 1, 0, 0);
- SetTimerEx(2.0, 1, 0, 0);
- SetTimerEx(5.0, 1, 0, 0);
- return;
-
- end
-